<template>
	<view class="page-body">
		<!-- 页面内容开始 -->

		<!-- 表格搜索组件开始 -->
		<vk-data-table-query v-model="queryForm1.formData" :columns="queryForm1.columns" @search="search">
		</vk-data-table-query>
		<!-- 表格搜索组件结束 -->

		<!-- 自定义按钮区域开始 -->
		<view v-if="vk.vuex.get('$user.userInfo.username')=='admin'">
			<el-row>
				<el-button type="success" size="small" icon="el-icon-circle-plus-outline" @click="addBtn">添加</el-button>

				<!-- 批量操作 -->
				<el-dropdown v-if="table1.multipleSelection" :split-button="false" trigger="click" @command="batchBtn">
					<el-button type="danger" size="small" style="margin-left: 20rpx;"
						:disabled="table1.multipleSelection.length === 0">
						批量操作<i class="el-icon-arrow-down el-icon--right"></i>
					</el-button>
					<el-dropdown-menu slot="dropdown">
						<el-dropdown-item :command="1">批量上架</el-dropdown-item>
						<el-dropdown-item :command="2">批量下架</el-dropdown-item>
					</el-dropdown-menu>
				</el-dropdown>
			</el-row>
		</view>
		<!-- 自定义按钮区域结束 -->

		<view v-if="vk.vuex.get('$user.userInfo.username')=='admin'">
			<!-- 表格组件开始 -->
			<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['detail_auto','update','delete','more']" :right-btns-more="table1.rightBtnsMore"
				:selection="true" :row-no="true" :pagination="true" @update="updateBtn" @delete="deleteBtn"
				@current-change="currentChange" @selection-change="selectionChange">
			</vk-data-table>
			<!-- 表格组件结束 -->
		</view>

		<view v-else>
			<!-- 表格组件开始 -->
			<vk-data-table ref="table1" :action="table1.action" :columns="table1.columns" :query-form-param="queryForm1"
				:right-btns="['more']" :right-btns-more="table1.rightBtnsMore" :selection="false" :row-no="true"
				:pagination="true" @current-change="currentChange" @selection-change="selectionChange">
			</vk-data-table>
			<!-- 表格组件结束 -->
		</view>


		<!-- 添加或编辑的弹窗开始 -->
		<vk-data-dialog v-model="form1.props.show" :title="form1.props.title" width="900px" mode="form"
			:close-on-click-modal="false">
			<vk-data-form v-model="form1.data" :rules="form1.props.rules" :action="form1.props.action"
				:form-type="form1.props.formType" :columns='form1.props.columns' label-width="140px"
				@success="form1.props.show = false;refresh();">

				<template v-slot:footer="{ loading }">
					<view style="text-align: center;">
						<el-button :loading="loading" type="danger" style="padding: 10px 40px;margin-right: 30px; "
							@click="form1.props.show=false"> 取消 </el-button>
						<el-button :loading="loading" type="success" style="padding: 10px 40px; "
							@click="batchAdd(form1.data)"> 确定
						</el-button>
					</view>
				</template>

			</vk-data-form>
		</vk-data-dialog>
		<!-- 添加或编辑的弹窗结束 -->

		<!-- 弹窗预览分集数据开始 -->
		<el-dialog title="分集数据预览" :visible.sync="dialogVisible" width="70%" :before-close="handleClose"
			:destroy-on-close="true" :center="true" :close-on-click-modal="false">
			<el-row>
				<el-col :span="12">
					<text style="font-size: large;margin-left: 10rpx;">当前播放:第{{currentserie}}集</text>
					<scroll-view scroll-y="true" style="height: 1250rpx;" :show-scrollbar="true">
						<block v-for="(item,index) in temp_series_list" :key="index">
							<el-button type="primary" @click="cut_serie(item)"
								style="width:170rpx;margin-bottom: 10rpx;margin-left: 10rpx;">第{{item.serie}}集
							</el-button>
						</block>
					</scroll-view>

				</el-col>
				<el-col :span="10">
					<view style="align-content: center;margin-left: 30rpx;">
						<video v-if="dialogVisible" ref="myVideo" id="myVideo" :src="currentlink" controls
							style="width: 700rpx;height: 1300rpx;" :autoplay="true"></video>
					</view>
				</el-col>
			</el-row>

			<span slot="footer" class="dialog-footer">
				<el-button @click="updata33()">切换备用源</el-button>
				<el-button @click="updata22()">重新获取</el-button>
				<el-button type="primary" @click="copylink">复制视频链接并下载</el-button>
			</span>
		</el-dialog>
		<!-- 弹窗预览分集数据结束 -->

		<!-- 页面内容结束 -->
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk = uni.vk; // vk实例
	var originalForms = {}; // 表单初始化数据
	const db = uniCloud.database();
	const OSS = require('ali-oss');
	export default {

		data() {
			// 页面数据变量
			return {
				store: {},
				baseurl: "",
				token: '',
				tv_name: '',
				album_id: '',
				tips: "请勿关闭浏览器...",
				currentserie: 0,
				currentlink: "", //当前播放视频链接
				temp_series_list: [],
				dialogVisible: false, //控制弹窗是否开启
				// 页面是否请求中或加载中
				loading: false,
				// init请求返回的数据
				data: {

				},
				// 表格相关开始 -----------------------------------------------------------
				table1: {
					rightBtnsMore: [

						{
							title: '分集数据',
							disabled: (item) => {
								//控制该按钮对哪些数据生效
								// return item._id == '63c54f03819ce8640cced33f'
							},
							async onClick(item) {
								console.log('item', item);
								that.tv_name = item.tv_name
								that.album_id = item.album_id
								that.currentserie = 1;
								that.currentlink = '';
								that.temp_series_list = [];
								vk.toast(`全剧共${item.all_series}集,已更新：` + item.update_witch);
								that.dialogVisible = true;
								// 判断是否有token
								console.log('1111111111', that.temp_series_list, item);

								vk.callFunction({
									url: 'admin/pages/pub/gitList3',
									title: '请求中...',
									data: {
										istoken: that.istoken,
										album_id: item.album_id,
										update_witch: item.update_witch
									},
									success: (data) => {
										console.log('122121', data);
										if (data.access_token) {
											that.istoken = data.access_token
										}
										that.temp_series_list = data.temp_series_list
										that.currentserie = that.temp_series_list[0].serie;
										that.currentlink = that.temp_series_list[0].link;
									}
								});

							}
						},
						{
							title: '一键填充剧集id',
							disabled: (item) => {
								//控制该按钮对哪些数据生效
								// return item._id == '63c54f03819ce8640cced33f'
							},
							async onClick(item) {
								console.log("item====", item);

								vk.callFunction({
									url: 'admin/pages/files_mzgl/dy_tv/kh/fillepisodeId',
									title: '请求中...',
									data: {
										_id: item._id,
										album_id: item.album_id
									},
									success: (data) => {

									}
								});
							}
						},
					],
					// 表格数据请求地址
					action: "admin/pages/kh/dsjzxgl/dsj/getList",
					// 表格字段显示规则
					columns: [{
							"key": "status",
							"title": "上架状态",
							"type": "tag",
							data: [{
									value: false,
									label: "下架",
									tagType: "default"
								},
								{
									value: true,
									label: "上架",
									tagType: "success"
								}
							]
						},
						{
							key: "",
							title: "主剧信息",
							type: "group",
							minWidth: 260,
							align: "left",
							columns: [{
									key: "tv_name",
									title: "剧名",
									type: "text"
								},
								{
									key: "_id",
									title: "主剧ID",
									type: "text"
								},
								{
									key: "album_id",
									title: "短剧ID",
									type: "text"
								},
							],
						},
						{
							key: "",
							title: "集数",
							type: "group",
							minWidth: 160,
							align: "left",
							columns: [{
									key: "all_series",
									title: "总集数",
									type: "number"
								},
								{
									key: "update_witch",
									title: "更新集数",
									type: "number"
								},
								{
									key: "is_end",
									title: "是否完结",
									type: "switch"
								}
							],
						},

						{
							"key": "tv_image",
							"title": "封面图",
							"type": "image"
						},

						{
							key: "",
							title: "弹窗起始集数",
							type: "group",
							minWidth: 160,
							align: "left",
							columns: [{
									key: "gzhbox_start",
									title: "弹窗开始集数",
									type: "number"
								},
								{
									key: "gzhbox_end",
									title: "弹窗结束集数",
									type: "number"
								},
							],
						},
						{
							"key": "erindex_cate",
							"title": "封面图",
							"type": "text"
						},
						// {
						// 	"key": "index_box",
						// 	"title": "推荐位",
						// 	"type": "tag",
						// 	"width": 100,
						// 	data: [{
						// 			value: 0,
						// 			label: "未推荐",
						// 			tagType: "default"
						// 		},
						// 		{
						// 			value: 1,
						// 			label: "好友力荐",
						// 			tagType: "success"
						// 		},
						// 		{
						// 			value: 2,
						// 			label: "独家推荐",
						// 			tagType: "warning"
						// 		},
						// 		{
						// 			value: 3,
						// 			label: "百万播放",
						// 			tagType: "error"
						// 		}
						// 	]
						// },
						// {
						// 	"key": "index_cate",
						// 	"title": "视频分类",
						// 	"type": "text"
						// },

						{
							key: "",
							title: "小程序信息",
							type: "group",
							minWidth: 230,
							align: "left",
							columns: [{
									key: "appid",
									title: "appid",
									type: "text",
									defaultValue: "未绑定"
								},
								{
									key: "appname",
									title: "小程序名称",
									type: "text",
									defaultValue: "未绑定"
								},
							],
							show: ["detail"]
						},

						// {"key":"all_like","title":"总点赞次数","type":"number"},
						{
							key: "",
							title: "标签信息",
							type: "group",
							minWidth: 160,
							align: "left",
							columns: [{
									key: "tag_color",
									title: "标签颜色",
									type: "text"
								},
								{
									key: "tag_text",
									title: "标签文字",
									type: "text"
								},
							],
						},

						// { "key": "desc", "title": "介绍", "type": "text" },
						{
							"key": "sort",
							"title": "排序",
							"type": "number"
						},
						{
							"key": "rank",
							"title": "排行榜名次",
							"type": "number",
							"width": 150,
							defaultValue: "未设置"
						},
						{
							"key": "_add_time_str",
							"title": "添加时间",
							"type": "text",
							"width": 200
						}
					],
					// 多选框选中的值
					multipleSelection: [],
					// 当前高亮的记录
					selectItem: ""
				},
				// 表格相关结束 -----------------------------------------------------------
				// 表单相关开始 -----------------------------------------------------------
				// 查询表单请求数据
				queryForm1: {
					// 查询表单数据源，可在此设置默认值
					formData: {

					},
					// 查询表单的字段规则 fieldName:指定数据库字段名,不填默认等于key
					columns: [{
							"key": "appid",
							"title": "appid",
							"type": "text",
							"width": 200,
							"mode": "%%"
						},
						{
							"key": "tv_name",
							"title": "电视剧名",
							"type": "text",
							"width": 200,
							"mode": "%%"
						},
						{
							"key": "album_id",
							"title": "短剧ID",
							"type": "text",
							"width": 200,
							"mode": "="
						},
						{
							key: "status",
							title: "状态",
							type: "select",
							data: [{
									value: true,
									label: "已上架"
								},
								{
									value: false,
									label: "已下架"
								},
							],
							"mode": "="
						}
					]
				},
				form1: {
					// 表单请求数据，此处可以设置默认值
					data: {
						//设置默认值
						tv_name: "",
						all_like: 0,
						sort: 1,
						is_end: false,
						gzhbox_start: 4,
						gzhbox_end: 12,
						tag_color: "#F20D0D",
						tag_text: "热播",
						cate: "精选短剧",
						index_cate: "独家好剧",
						index_box: 0,
						start_needpay: 12,
						how_much: 99,
						batch_add: true,
						status: true,
						appid: [],
						appname: [],
						querykey: "key",
						tv_class: "",
						allow_ads: false
					},
					// 表单属性
					props: {
						// 表单请求地址
						action: "",
						// 表单字段显示规则
						columns: [{
								"key": "status",
								"title": "上架状态",
								"type": "switch",
								"show": ["add"]
							},
							// {
							// 	key: "",
							// 	title: "短剧分类",
							// 	type: "table-select",
							// 	placeholder: "选择",
							// 	action: "admin/pages/kh/dsjzxgl/djfl/getList",
							// 	columns: [{
							// 		"key": "classify",
							// 		"title": "类别",
							// 		"type": "text",
							// 		"width": 200,
							// 		nameKey: true,
							// 	}, ],
							// 	watch: (res) => {
							// 		console.log("res.option.classify=", res.option.classify);
							// 		this.form1.data.tv_class = res.option.classify;
							// 		this._data.form1.data.tv_class = res.option.classify
							// 	}
							// },
							{
								"key": "tv_name",
								"title": "剧名",
								"type": "text"
							},
							{
								"key": "album_id",
								title: "短剧ID",
								type: "table-select",
								placeholder: "请选择短剧id",
								// multiple: true,
								queryColumns: [{
										key: "album_id",
										title: "剧目id",
										type: "text",
										width: 150,
										mode: "%%"
									},
									{
										key: "album_info.title",
										title: "剧目名称",
										type: "text",
										width: 150,
										mode: "%%"
									}
								],
								"action": "admin/pages/files_mzgl/page_binding/kh/djid",
								"columns": [{
										key: "album_id",
										title: "剧目id",
										type: "text",
										idKey: true,

									}, {
										key: "title",
										title: "剧目名称",
										type: "text",
										nameKey: true,
									}

								],
							},

							{
								"key": "tv_image",
								"title": "封面图",
								"type": "file-select",
								"placeholder": "请选择图片",
								"fileType": "image",
								"limit": 1
							},
							// {
							// 	"key": "baseurl",
							// 	"title": "视频目录",
							// 	"type": "text",
							// 	"tips": "一定要按照以下示例填写，以/结尾，后面不要带1.mp4之类的，如：https://xxx.oss-cn-hangzhou.aliyuncs.com/xiyouji/"
							// },
							{
								"key": "all_series",
								"title": "总集数",
								"type": "number",
								"placeholder": "该剧总集数，填写数字即可"
							},
							{
								"key": "update_witch",
								"title": "已更新数",
								"type": "number",
								"placeholder": "该剧已更新到多少集"
							},
							{
								"key": "is_end",
								"title": "是否完结",
								"type": "switch"
							},
							// { "key": "allow_ads", "title": "允许看广告解锁", "type": "switch" },
							{
								"key": "start_needpay",
								"title": "哪一集开始收费",
								"type": "number",
								"tips": "仅添加时生效，修改不生效"
							},
							{
								"key": "how_much",
								"title": "每集多少金豆",
								"type": "number",
								"tips": "仅添加时生效，修改不生效"
							},
							{
								"key": "gzhbox_start",
								"title": "抖音号弹窗开始集",
								"type": "number",
								"tips": "填写纯数字，第几集开始抖音号弹窗"
							},
							{
								"key": "gzhbox_end",
								"title": "抖音号弹窗结束集",
								"type": "number",
								"tips": "填写纯数字，第几集结束抖音号弹窗"
							},
							{
								"key": "sort",
								"title": "排序",
								"type": "number",
								"placeholder": "排序值越小排序越靠前"
							},
							{
								"key": "rank",
								"title": "排行名次",
								"type": "number",
								"placeholder": "在排行榜排多少名"
							},
							// {
							// 	key: "index_cate",
							// 	title: "视频分类",
							// 	type: "select",
							// 	data: [{
							// 			value: "最新热剧",
							// 			label: "最新热剧"
							// 		},
							// 		{
							// 			value: "独家好剧",
							// 			label: "独家好剧"
							// 		},
							// 		{
							// 			value: "逆袭剧场",
							// 			label: "逆袭剧场"
							// 		},
							// 		{
							// 			value: "热血剧场",
							// 			label: "热血剧场"
							// 		},
							// 		{
							// 			value: "情感剧场",
							// 			label: "情感剧场"
							// 		},
							// 		{
							// 			value: "其它",
							// 			label: "其它"
							// 		}
							// 	],
							// 	showRule: () => {
							// 		// return false;
							// 	}
							// },
							{
								key: "erindex_cate",
								title: "二级页面视频分类",
								type: "remote-select",
								action: (obj = {}) => {
									let {
										data, // 请求数据
										success, // 成功回调
										fail, // 失败回调
										complete, // 成功回调
									} = obj;
									// 发起http请求
									vk.callFunction({
										url: "client/pages/pub/index_appdata",
										data: {
											appid: 1
										},

										success: (res) => {
											console.log('6666', res.active.fl_tags);
											if (typeof success === "function") {
												let list = res.active.fl_tags.map((item, index) => {
													return {
														value: item,
														label: item
													}
												});
												success({
													list: list
												});
											}
										},
										fail: (res) => {
											if (typeof fail === "function") fail(res);
										},
										complete: (res) => {
											if (typeof complete === "function") complete(res);
										}
									});
								}
							},
							{
								key: "desc",
								title: "剧情介绍",
								type: "textarea",
								autosize: {
									minRows: 3,
									maxRows: 10
								},
								maxlength: 300,
								showWordLimit: true,
							},

							{
								key: "appname",
								title: "绑定小程序",
								tips: "不选则在所有小程序展示",
								type: "table-select",
								placeholder: "选择",
								action: "admin/pages/kh/xcxpz/xcxgl/getList",
								columns: [{
										key: "appid",
										title: "小程序appid",
										type: "text",
										nameKey: true
									},
									{
										key: "appname",
										title: "小程序名称",
										type: "text",
										idKey: true
									},
								],
								multiple: true,
								watch: (res) => {
									// console.log("watch", res.option)
									this.form1.data.appid = vk.pubfn.arrayObjectGetArray(res.option, "appid");
								}
							},
							{
								"key": "appname",
								"title": "小程序名称",
								"type": "array<string>",
								"tips": "不选表示在所有小程序展示"
							},
							// { "key": "appid", "title": "appid", "type": "array<string>", "tips": "不选表示在所有小程序展示" },

							// {
							// 	"key": "all_like",
							// 	"title": "总赞次数",
							// 	"type": "number"
							// },
							{
								"key": "tag_text",
								"title": "标签文字",
								"type": "text"
							},
							{
								"key": "tag_color",
								"title": "标签颜色",
								"type": "color"
							},
							{
								"key": "querykey",
								"title": "查询密钥",
								"type": "text",
								tips: "版权方查询该部剧的充值记录时需要此密钥"
							},

							// {
							// 	key: "index_box",
							// 	title: "推荐位",
							// 	type: "select",
							// 	data: [{
							// 			value: 0,
							// 			label: "不推荐"
							// 		},
							// 		{
							// 			value: 1,
							// 			label: "好友力荐"
							// 		},
							// 		{
							// 			value: 2,
							// 			label: "独家推荐"
							// 		},
							// 		{
							// 			value: 3,
							// 			label: "百万播放"
							// 		}
							// 	],
							// 	showRule: () => {
							// 		// return false;
							// 	}
							// },
							{
								"key": "batch_add",
								"title": "是否批量添加集数",
								"type": "switch",
								"tips": "特别注意：开启此项请务必正确填写【视频目录】",
								"show": ["add"]
							}
						],
						// 表单验证规则
						rules: {
							tv_name: [{
								required: true,
								message: "剧名必须填写",
								trigger: ['blur', 'change']
							}],
							album_id: [{
								required: true,
								message: "短剧ID必须填写",
								trigger: ['blur', 'change']
							}],
							tv_image: [{
								required: true,
								message: "封面图必填",
								trigger: ['blur', 'change']
							}],
							// baseurl: [{
							// 	required: true,
							// 	message: "视频目录必填",
							// 	trigger: ['blur', 'change']
							// }],
							gzhbox_start: [{
								required: true,
								message: "第几集开始弹出关注抖音号提醒",
								trigger: ['blur', 'change']
							}],
							gzhbox_end: [{
								required: true,
								message: "第几集结束弹出关注抖音号提醒",
								trigger: ['blur', 'change']
							}],
							// cate: [{
							// 	required: true,
							// 	message: "分类必填",
							// 	trigger: ['blur', 'change']
							// }],
							// index_cate: [{
							// 	required: true,
							// 	message: "分类必填",
							// 	trigger: ['blur', 'change']
							// }],
							all_series: [{
									required: true,
									message: "必须填写总集数，且必须是纯数字",
									trigger: ['blur', 'change']
								},
								{
									type: "number",
									message: "必须是数字",
									trigger: ['blur', 'change']
								}
							],
							start_needpay: [{
								required: true,
								message: "开始付费集数必填",
								trigger: ['blur', 'change']
							}],
							how_much: [{
								required: true,
								message: "付费金额必填",
								trigger: ['blur', 'change']
							}],
							update_witch: [{
								required: true,
								message: "更新集数必填",
								trigger: ['blur', 'change']
							}],
							tag_text: [{
								required: true,
								message: "标签必填",
								trigger: ['blur', 'change']
							}],
							// index_box: [{
							// 	required: true,
							// 	message: "不可为空",
							// 	trigger: ['blur', 'change']
							// }],
						},
						// add 代表添加 update 代表修改
						formType: "",
						// 是否显示表单的弹窗
						show: false
					}
				},
				// 其他弹窗表单
				formDatas: {},
				// 表单相关结束 -----------------------------------------------------------
			};
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.options = options;
			that.init(options);
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		async onReady() {
			const alioss = await db.collection('a_config').where({
				name: "alioss"
			}).get();
			// vk.setVuex('$app.ossinfo', ossinfo) //把阿里云oss配置存到本地缓存	

			// if (alioss.result.data[0]) {
			// 	let ossinfo = alioss.result.data[0];
			// 	this.store = new OSS({
			// 		// yourRegion填写Bucket所在地域。以华东1（杭州）为例，yourRegion填写为oss-cn-hangzhou。
			// 		region: ossinfo.region,
			// 		// 阿里云账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维，请登录RAM控制台创建RAM用户。
			// 		accessKeyId: ossinfo.accessKeyId,
			// 		accessKeySecret: ossinfo.accessKeySecret,
			// 		// 填写Bucket名称。
			// 		bucket: ossinfo.bucket
			// 	});
			// 	this.baseurl = ossinfo.baseurl;
			// } else {
			// 	this.store = new OSS({
			// 		// yourRegion填写Bucket所在地域。以华东1（杭州）为例，yourRegion填写为oss-cn-hangzhou。
			// 		region: "test",
			// 		// 阿里云账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维，请登录RAM控制台创建RAM用户。
			// 		accessKeyId: "test",
			// 		accessKeySecret: "test",
			// 		// 填写Bucket名称。
			// 		bucket: "test",
			// 	});
			// 	this.baseurl = ""
			// }
		},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {
			console.log("oss=", vk.vuex.get('$app.ossinfo.region'));
		},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		methods: {
			// async getSecUrl(tempUrl) {
			// 	//如果数据库里没配置相关参数，则原样返回
			// 	if (!this.baseurl) {
			// 		return tempUrl;
			// 	}
			// 	let suffix = tempUrl.substr(-4); //截取后四位,如果后4位不是.mp4，说明已经获取过签名
			// 	console.log("suffix=", suffix);
			// 	if (suffix == ".mp4" || suffix == ".MP4") {
			// 		//避免有些文件是http，因此统一替换成https
			// 		tempUrl = tempUrl.replace('http://', 'https://');
			// 		//清空域名信息，只留文件名信息，例如：anna/1.mp4
			// 		let videoFile = tempUrl.replace(this.baseurl, '');
			// 		//生成带签名的url
			// 		let url = this.store.signatureUrl(videoFile, {
			// 			expires: 3600, //3600秒到期
			// 		});
			// 		return url;
			// 	} else {
			// 		return tempUrl;
			// 	}

			// },
			async batchAdd(item) {
				//如果已存在_id,就是编辑，否则就是新增（此处只能是已_id为判定条件）
				if (item._id) {
					vk.callFunction({
						url: 'admin/pages/kh/dsjzxgl/dsj/update',
						title: '请求中...',
						data: {
							tvinfo: this.form1.data
						},
						success: (data) => {
							this.form1.props.show = false; //关闭编辑窗口
							this.refresh()
						}
					});
					return;
				} else {
					if (!this.form1.data.update_witch) {
						vk.alert('必须填写更新集数');
						return;
					}

					if (!this.form1.data.tv_name || !this.form1.data.tv_image || !this
						.form1.data.album_id) {
						vk.alert('参数不完整，请检查必填项');
						return;
					}

					if (!this.form1.data.all_series || !this.form1.data.start_needpay || !this.form1.data.how_much) {
						vk.alert('参数不完整，请检查必填项');
						return;
					}

					if (this.form1.data.gzhbox_start == "" || this.form1.data.gzhbox_end == "" || !this.form1.data
						.tag_text) {
						if (this.form1.data.gzhbox_start != 0 || this.form1.data.gzhbox_end != 0) {
							vk.alert('参数不完整，请检查必填项');
							return;
						}
					}

					// if (this.form1.data.tv_class == "") {
					// 	vk.alert('短剧分类必须填写，请检查必填项');
					// 	return;
					// }

					let timenow = new Date().getTime();
					let addtv = await db.collection('a_tv').add({
						status: this.form1.data.status, //上下架的状态
						tv_name: this.form1.data.tv_name, //剧名
						album_id: this.form1.data.album_id, // 短剧ID
						tv_image: this.form1.data.tv_image, //封面图
						// baseurl: this.form1.data.baseurl, //目录路径
						all_series: this.form1.data.all_series, //总集数
						update_witch: this.form1.data.update_witch, //更新到哪一集
						allow_ads: this.form1.data.allow_ads, //允许看广告解锁
						is_end: this.form1.data.is_end, //是否结束
						sort: this.form1.data.sort, //排序
						rank: this.form1.data.rank || 1, //排行名词
						// cate: this.form1.data.cate, //分类
						// index_cate: this.form1.data.index_cate, //首页分类
						desc: this.form1.data.desc, //描述
						// all_like: this.form1.data.all_like, //总赞数
						tag_color: this.form1.data.tag_color, //标签颜色
						tag_text: this.form1.data.tag_text, //标签文字
						// index_box: this.form1.data.index_box, //推荐位
						start_needpay: this.form1.data.start_needpay, //哪一集开始收费
						how_much: this.form1.data.how_much, //每集多少金豆
						gzhbox_start: this.form1.data.gzhbox_start, //公众号弹窗开始集
						gzhbox_end: this.form1.data.gzhbox_end, //公众号弹窗结束集
						appid: this.form1.data.appid, //绑定的appid
						appname: this.form1.data.appname,
						querykey: this.form1.data.querykey, //查询秘钥
						// tv_class: this.form1.data.tv_class, //短剧分类
						_add_time: timenow,
						_add_time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss")
					})

					if (!this.form1.data.batch_add) {
						console.log("未开启批量添加");
						vk.alert('已完成，本次未开启批量添加');
						this.form1.props.show = false; //关闭编辑窗口
						this.refresh()
						return;
					}

					let update_series = this.form1.data.update_witch;
					for (var i = 0; i < update_series; i++) {
						uni.showToast({
							title: i + "/" + update_series + "，请勿关闭浏览器...",
							icon: 'loading'
						})
						let like_num = vk.pubfn.random(3);
						let serie = i + 1;
						let pay_bean = this.form1.data.how_much; //初始值为前端传过来的how_much金豆
						//未到收费集数，则收费为0
						if (serie < this.form1.data.start_needpay) {
							pay_bean = 0
						}
						let add = await db.collection('a_tv_series').add({
							tv_id: addtv.result.id,
							album_id: this.form1.data.album_id,
							tv_name: this.form1.data.tv_name,
							series: serie,
							tv_image: this.form1.data.tv_image,
							// video_src: this.form1.data.baseurl,
							like_num: like_num * 1,
							pay: pay_bean,
							title: this.form1.data.tv_name + " - 第" + serie + "集",
							is_recommend: false,
							appid: [],
							appname: [],
							_add_time: timenow,
							_add_time_str: vk.pubfn.timeFormat(new Date(), "yyyy-MM-dd hh:mm:ss") || "0"
						})
					}
					this.form1.props.show = false; //关闭编辑窗口
					vk.alert('恭喜！添加完成');
					this.refresh()
				}
			}, //切换数据源
			updata22() {
				vk.callFunction({
					url: 'admin/pages/pub/gitList3',
					title: '请求中...',
					data: {
						istoken: that.istoken,
						album_id: that.album_id,
						updata: true
					},
					success: (data) => {
						console.log('122121', data);
						if (data.access_token) {
							that.istoken = data.access_token
						}
						that.temp_series_list = data.temp_series_list
						that.currentserie = that.temp_series_list[0].serie;
						that.currentlink = that.temp_series_list[0].link;
					}
				});

			}, //切换备用源
			updata33() {
				vk.callFunction({
					url: 'admin/pages/pub/gitList3',
					title: '请求中...',
					data: {
						istoken: that.istoken,
						album_id: that.album_id,

						back: true
					},
					success: (data) => {
						console.log('122121', data);
						if (data.access_token) {
							that.istoken = data.access_token
						}
						that.temp_series_list = data.temp_series_list
						that.currentserie = that.temp_series_list[0].serie;
						that.currentlink = that.temp_series_list[0].link;
					}
				});

			},
			copylink() {
				let that = this;
				uni.downloadFile({
					url: this.currentlink,
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success: (res) => {
						console.log(res);
					},
					complete: (res) => {
						console.log(res);
					},
				});
				uni.setClipboardData({
					data: this.currentlink,
					success() {
						// vk.toast('复制成功', 'none');
						that.$message({
							message: '视频链接复制成功',
							type: 'success'
						});
					}
				})
			}, //更换播放倍数
			// 点按钮换集
			async cut_serie(item) {
				// vk.toast(link, 'none');
				//获取带签名的视频地址
				let newUrl = item.link
				console.log("newUrl=", newUrl);
				this.currentlink = newUrl;
				this.currentserie = item.serie;

			},
			//弹窗关闭前做一下判断或操作
			handleClose() {
				this.dialogVisible = false;
			},
			// 页面数据初始化函数
			init(options) {
				originalForms["form1"] = vk.pubfn.copyObject(that.form1);
			},
			// 页面跳转
			pageTo(path) {
				vk.navigateTo(path);
			},
			// 表单重置
			resetForm() {
				vk.pubfn.resetForm(originalForms, that);
			},
			// 搜索
			search() {
				that.$refs.table1.search();
			},
			// 刷新
			refresh() {
				that.$refs.table1.refresh();
			},
			// 获取当前选中的行的数据
			getCurrentRow() {
				return that.$refs.table1.getCurrentRow();
			},
			// 监听 - 行的选中高亮事件
			currentChange(val) {
				that.table1.selectItem = val;
			},
			// 当选择项发生变化时会触发该事件
			selectionChange(list) {
				that.table1.multipleSelection = list;
			},
			// 显示添加页面
			addBtn() {
				that.resetForm();
				that.form1.props.action = 'admin/pages/kh/dsjzxgl/dsj/add';
				that.form1.props.formType = 'add';
				that.form1.props.title = '添加';
				that.form1.props.show = true;
			},
			// 显示修改页面
			updateBtn({
				item
			}) {
				that.form1.props.action = 'admin/pages/kh/dsjzxgl/dsj/update';
				that.form1.props.formType = 'update';
				that.form1.props.title = '编辑';
				that.form1.props.show = true;
				that.form1.data = item;
			},
			// 删除按钮
			deleteBtn({
				item,
				deleteFn
			}) {
				deleteFn({
					action: "admin/pages/kh/dsjzxgl/dsj/delete",
					data: {
						_id: item._id
					},
				});
			},
			// 监听 - 批量操作的按钮点击事件
			batchBtn(index) {
				switch (index) {
					case 1:
						vk.callFunction({
							url: 'admin/pages/kh/dsjzxgl/dsj/batchup',
							title: '请求中...',
							data: {
								lists: this.table1.multipleSelection
							},
							success: (data) => {
								console.log("执行完成");
								this.refresh()
							}
						});
						break;
					case 2:
						vk.callFunction({
							url: 'admin/pages/kh/dsjzxgl/dsj/batchdown',
							title: '请求中...',
							data: {
								lists: this.table1.multipleSelection
							},
							success: (data) => {
								console.log("执行完成");
								this.refresh()
							}
						});
						break;
					default:
						break;
				}
			}
		},
		// 监听属性
		watch: {

		},
		// 过滤器
		filters: {

		},
		// 计算属性
		computed: {

		}
	};
</script>
<style lang="scss" scoped>
	.page-body {}

	// 滚动条样式
	/deep/ ::-webkit-scrollbar {
		/*滚动条整体样式*/
		width: 4px !important;
		height: 1px !important;
		overflow: auto !important;
		background: #ccc !important;
		-webkit-appearance: auto !important;
		display: block;
	}

	/deep/ ::-webkit-scrollbar-thumb {
		/*滚动条里面小方块*/
		border-radius: 10px !important;
		box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
		background: #7b7979 !important;
	}

	/deep/ ::-webkit-scrollbar-track {
		/*滚动条里面轨道*/
		// box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2) !important;
		// border-radius: 10px !important;
		background: #FFFFFF !important;
	}
</style>